#include "pagecontrol.h"

PageControl::PageControl()
{
    login = NULL;
    regist = NULL;
    home = NULL;
}


PageControl::~PageControl()
{

}

void PageControl::toPage(QString page)
{
    if(page=="login")
    {
       toLoginPage();
    }
    if(page=="register")
    {
       toRegisterPage();
    }
}


void PageControl::show()
{
    toLoginPage();
}

void PageControl::toLoginPage()
{
    if(login == NULL)
    {
        login = new LoginPage();
        connect(login,&LoginPage::toPage,
                this,&PageControl::toPage);
        connect(login,&LoginPage::toPage,
                this,[this](){
            delete login;
            login =NULL;
        });
    }
    login->show();
}

void PageControl::toRegisterPage()
{
    if(regist==NULL)
    {
        regist = new RegisterPage();
        connect(regist,&RegisterPage::toPage,
                this,&PageControl::toPage);
        connect(regist,&RegisterPage::destory,
                this,[this](){
            delete regist;
            regist = NULL;
        });
    }
    regist->show();
}

void PageControl::toHomePage()
{
    if(home == NULL)
    {
        home = new HomePage();
        connect(home,&HomePage::toPage,
                this,&PageControl::toPage);
        connect(home,&HomePage::destory,
                this,[this](){
            delete home;
            home = NULL;
        });
    }
}


